package com.qf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.dto.PageDto;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsCommentService;
import com.qf.util.ResponseUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/24 22:18
 */

@RestController
@RequestMapping("/admin/comment")
@Slf4j
@CrossOrigin
public class CommonController {
    @Autowired
    private DtsCommentService dtsCommentService;
    @RequiresPermissionsDesc(menu = {"商场管理","商品评论"},button ="查找")
    @RequiresPermissions("admin:comment:list")
    @GetMapping("/list")
    public Object commentList( PageDto pageDto) {
        // http://localhost:8080/admin/comment/list?page=1&limit=20&userId=ss&valueId=aa&sort=add_time&order=desc

        Page<DtsComment> dtsCommentPage = dtsCommentService.selectPage(pageDto.getLimit(), pageDto.getPage(), pageDto.getOrder(), pageDto.getSort(), pageDto.getUserId(), pageDto.getValueId());

        long total = dtsCommentPage.getTotal();
        List<DtsComment> records = dtsCommentPage.getRecords();
        HashMap<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", records);
        return ResponseUtil.ok(data);

    }
    //'http://localhost:8080/admin/order/reply
    @RequiresPermissionsDesc(menu = {"商场管理","商品评论"},button ="删除")
    @RequiresPermissions("admin:comment:delete")
    @PostMapping("/delete")
    public  Object commonDelete(@RequestBody DtsComment dtsComment) {
        dtsComment.setDeleted(true);
        dtsCommentService.delete(dtsComment);
        return ResponseUtil.ok();
    }
}
